<?php

//$GLOBALS['Md'] = "RHUSJW24";
//$GLOBALS['Pd'] = "B";


//echo "entrei aqui";

include($GLOBALS['LNG'].$_SESSION[$SESSLG]."/main.settings.php");
include($GLOBALS['LNG'].$_SESSION[$SESSLG]."/mod.clients.php");

require_once($_SERVER['DOCUMENT_ROOT'].'/defaultconf.mex');

//require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
//require_once($GLOBALS['PAD']."Modules/RHUSJW24/modconf.mex"); 

MYTCONN();

$user = $GLOBALS['MYT']->db_array("SELECT main_users.name as name_user , main_users.staffmember as user_staff, main_offices.name as name_office FROM systemoffice.main_users inner join systemoffice.main_offices on main_users.ref_office = main_offices.ref where main_users.ref = {$_SESSION[$SESSID]} ");
//$staff_member = $user[1]['staffmember'];
//$loja = $GLOBALS['MYT']->db_array("SELECT name FROM systemoffice.main_offices where ref = {$_SESSION[$SESSOF]} ");

//echo $user[1]['name'];
//echo $user[1]['staffmember'];

//if($user[1]['name'] == "Administrator" || $user[1]['name'] == "Akley" || $user[1]['name'] == "jduartecmr" || $user[1]['name'] == "maraujocmr" || $user[1]['name'] == "lmachado"){
	if($user[1]['name_office'] == "Sede" || $user[1]['name_office'] == "Departamento Comercial" ){
	$GET = $GLOBALS['MYT']->db_array("SELECT
			ref AS ref,
			main_users_ref AS user,
			main_office_ref AS balcao,
			Data_Pedido AS data,
			estado AS estado,
			pedido AS pedido,
			data_visita as data_vis,
			comercial as comercial,
			obs as obs
			FROM systemoffice.comercial_request ");
				
	$SIZE = $GET[0];
	}
	

//echo $GET[1]['user'];
	
			?>
	


<div id="User_List"></div>

<script charset="utf-8" type="text/javascript">
 var  windowHeight = document.documentElement.clientHeight-180;

Ext.onReady(function(){

    var myData = [
	<?php   
	
	//'".trimall($GET[$i]['pedido'])."'
	for ($i=1;$i<=$SIZE;$i++) {
	echo "[{$i},'{$GET[$i]['ref']}','{$GET[$i]['user']}','{$GET[$i]['balcao']}','{$GET[$i]['data']}','{$GET[$i]['estado']}','".trimall($GET[$i]['pedido'])."','{$GET[$i]['data_vis']}','{$GET[$i]['comercial']}','".trimall($GET[$i]['obs'])."']";
		if ($i<$SIZE) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'ref', type: 'int'},
               {name: 'user', type: 'string'},
               {name: 'balcao', type: 'string'},
               {name: 'data', type: 'string'},
			   {name: 'estado', type: 'string'},
               {name: 'pedido', type: 'string'},
               {name: 'data_vis', type: 'string'},
			   {name: 'comercial', type: 'string'},
               {name: 'obs', type: 'string'}
          ])
    });
	
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Ref", width: 60, sortable: true, locked:true, dataIndex: 'ref'},
        {header: "User", width: 80, sortable: true, locked:true, dataIndex: 'user'},
        {header: "Balcao", width: 150, sortable: true, dataIndex: 'balcao'},
        {header: "Data", width: 150, sortable: true, locked:true,dataIndex: 'data'},
        {header: "Estado", width: 70, sortable: true, locked:true,dataIndex: 'estado'},
        {header: "Pedido", width: 160, sortable: true, locked:true,dataIndex: 'pedido'},
        {header: "Data Visita", width: 150, sortable: true, locked:true,dataIndex: 'data_vis'},
	    {header: "Comercial", width: 110, sortable: true, locked:true,dataIndex: 'comercial'},
		{header: "Obs", width: 120, sortable: true, locked:true,dataIndex: 'obs'}
    ]);

   var selmode = new Ext.grid.RowSelectionModel({});
   
   
   var Console = new Ext.grid.GridPanel({
	            ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('ref');	
					idwindow('Propriedades do Pedido','user_properties','user_form','modules/Pedido a Comerciais/change_pedido_status.php?RSID='+value,710,550);
					 }
				},
	    height:  windowHeight ,
        renderTo: 'User_List'
    });
		
});
</script>